package org.example.library.aspect;

import lombok.extern.slf4j.Slf4j;
import org.aspectj.lang.ProceedingJoinPoint;
import org.aspectj.lang.annotation.Around;
import org.aspectj.lang.annotation.Aspect;
import org.springframework.stereotype.Component;

@Slf4j
@Aspect
@Component
public class TimeAspect {
    @Around("execution(* org.example.library.controller.*.*(..))")
    public Object timeRecord(ProceedingJoinPoint jp) throws Throwable {
        //记录开始时间
        long start=System.currentTimeMillis();
        //执行目标方法
        Object result = jp.proceed();
        //记录结束时间
        long cost=System.currentTimeMillis()-start;
        log.info(jp.getSignature()+"耗时：{} ms",cost);
        return result;
    }
}
